<script setup lang="ts">
import { ref, computed, nextTick, onMounted,reactive } from "vue";
import { ruleSeting} from "@/api/system";
import { useI18n } from "vue-i18n";
const { t } = useI18n();
import {message} from "@/utils/message";
defineOptions({
  name: "SystemRuleSet"
});

const form = reactive({
  delivery_auto: false,
  delivery_auto_size: false,
  expire_day: 3,
  aysc_hour: 6,
})


onMounted(() => {
  onSearch();
});
async function onSearch() {
  const { data } = await ruleSeting();
  form.delivery_auto = data.delivery_auto
  form.delivery_auto_size = data.delivery_auto_size
  form.expire_day = data.expire_day
  form.aysc_hour = data.aysc_hour
}


const onSubmit = () => {
  function chores(r,type=1) {
    message(`修改成功`, {
      type: "success"
    });
  }
  ruleSeting(form,"post").then(r=>chores(r,1)).catch(r=>chores(r,2))
}
</script>

<template>
  <div class="main">
    <el-card shadow="never">
      <template #header>
        <div class="card-header">
        业务规则设置
        </div>
      </template>
      <el-form :model="form" label-width="auto" style="max-width: 600px">
        <div class="font-medium custom-block tip">
          业务规则
        </div>
        <el-form-item label="开发采购自动派单">
          <el-switch v-model="form.delivery_auto" />
        </el-form-item>
        <el-form-item label="实物尺寸自动派单">
          <el-switch v-model="form.delivery_auto_size" />
        </el-form-item>

        <div class="font-medium custom-block tip">
          业务规则
        </div>
        <el-form-item label="">
          配货中超过
          <el-input-number v-model="form.expire_day" :min="1" :max="10" style="margin: 0 5px" controls-position="right"/>天未发货的订单预警
        </el-form-item>
        <el-form-item label="">
          马帮订单每
          <el-input-number v-model="form.aysc_hour" :min="1" :max="12" style="margin: 0 5px" controls-position="right"/>小时同步一次
        </el-form-item>


        <el-form-item>
          <el-button type="primary" @click="onSubmit">{{ $t("buttons.save") }}</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<style lang="scss" scoped>
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}
.custom-block.tip {
  padding: 3px 16px;
  border-left: 5px solid var(--el-color-primary);
  margin-bottom: 20px;
  border-bottom: 1px solid var(--el-border-color-light);
}
.main-content {
  margin: 24px 24px 0 !important;
}

.search-form {
  :deep(.el-form-item) {
    margin-bottom: 12px;
  }
}
</style>
